<template>
  <div>
    <el-row class="elRow" :gutter="30" type="flex" justify="start">
      <el-col :span="6">
        <span class="large">{{ $t('market.workshop') }}<!--生产车间--></span>
        <el-autocomplete
          ref="custom"
          v-model.trim="company.fworkshop"
          highlight-first-item
          popper-class="my-autocomplete"
          :fetch-suggestions="querySearch18"
          size="mini"
          class="input-width"
          :disabled="detailDisabled"
          @focus="getBasicUnit('SX_V_WORKSHOP')"
          @select="selUnit"
        >
          <i
            slot="suffix"
            class="el-input__icon el-icon-search"
            @click="cliUnit('SX_V_WORKSHOP')"
          />
          <template slot-scope="{ item }">
            <div class="name">{{ item.fname }}</div>
          </template>
        </el-autocomplete>
      </el-col>
      <el-col :span="6">
        <span class="large">{{ $t('market.produceUnit') }}<!--生产单位--></span>
        <el-input
          v-model.trim="company.fproduceUnit"
          size="mini"
          class="input-width"
          disabled
        />
      </el-col>
      <el-col :span="6">
        <span class="large">{{ $t('market.overrate') }}<!--入库超收比例(%)--></span>
        <el-input-number
          v-model="company.ffinishreceiptoverRate"
          controls-position="right"
          size="mini"
          :min="0"
          :disabled="detailDisabled"
        />
      </el-col>
      <el-col :span="6">
        <span class="large">{{ $t('market.shortrate') }}<!--入库欠收比例(%)--></span>
        <el-input-number
          v-model="company.ffinishreceiptshortRate"
          controls-position="right"
          size="mini"
          :min="0"
          :disabled="detailDisabled"
        />
      </el-col>
      <el-col :span="6">
        <span class="large">{{ $t('market.issueType') }}<!--发料方式--></span>
        <el-select
          v-model="company.fissueType"
          size="mini"
          :disabled="detailDisabled"
          class="input-width"
        >
          <el-option v-for="item in storeData" :key="item.fid" :label="item.fname" :value="item.fid" />
        </el-select>
      </el-col>
      <el-col :span="6">
        <span class="large">{{ $t('market.pickStock') }}<!--发料仓库--></span>
        <el-autocomplete
          v-model="company.fpickStock"
          popper-class="my-autocomplete"
          :fetch-suggestions="querySearch21"
          placeholder="请输入内容"
          size="mini"
          class="input-width"
          :disabled="detailDisabled"
          @focus="handleWarehouse"
          @select="warehouseSelectRow"
        >
          <i
            v-show="!detailDisabled"
            slot="suffix"
            class="el-input__icon el-icon-search"
            @click="openWarehouse = true"
          />
          <template slot-scope="{ item }">
            <div class="name">{{ item.fname }}</div>
          </template>
        </el-autocomplete>
      </el-col>
      <el-col :span="6">
        <span class="large">{{ $t('market.pickbinId') }}<!--发料仓位--></span>
        <el-input
          v-model="company.fpickbinId"
          placeholder="请输入仓位"
          size="mini"
          class="input-width"
          :disabled="detailDisabled"
        />
      </el-col>
      <el-col :span="6">
        <span class="large" />
        <el-checkbox v-model="company.fproducecheck">{{ $t('market.producecheck') }}<!--是否生产检验--></el-checkbox>
      </el-col>
    </el-row>
    <unit v-if="unitVisabled" :msg="funit" @unit="selUnit" />
    <!--    仓库-->
    <selectCK v-if="openWarehouse" @client="warehouseSelectRow" />
  </div>
</template>

<script>
import autocomplete from '@/views/market/marketManage/createMarkerOrder/components/autocomplete'
import { queryViewItem } from '@/api/marketManage/marketOrder'

export default {
  components: {
    selectCK: () => import('@/views/production/collect/components/seleceCK'),
    unit: () => import('@/views/basic/createMateriel2/components/unit')
  },
  mixins: [autocomplete],
  props: {
    company: {
      type: Object,
      default: () => {
        return {}
      }
    },
    unit: {
      type: Object,
      default: () => {
        return {}
      }
    },
    detailDisabled: {
      type: Boolean,
      default: false
    },
    detailShow: {
      type: Boolean,
      default: true
    }
  },
  data() {
    return {
      unitVisabled: false,
      funit: '',
      storeData: [], // 发料方式
      openWarehouse: false // 仓库弹窗
    }
  },
  watch: {
    unit(ev) {
      this.$set(this.company, 'fproduceunitId', ev.fid)
      this.$set(this.company, 'fproduceUnit', ev.fname)
    }
  },
  created() {
    this.handleGetMaterials() // 发料方式
  },
  methods: {
    cliUnit(ev) {
      this.funit = ev
      this.unitVisabled = true
    },
    // 生产单位
    selUnit(ev) {
      if (ev.fid) {
        if (this.funit === 'SX_V_WORKSHOP') { // 生产车间
          this.company.fworkshopId = ev.fid
          this.company.fworkshop = ev.fname
        } else if (this.funit === 'SX_V_UNIT_PRODUCE') { // 生产单位
          this.company.fproduceunitId = ev.fid
          this.company.fproduceUnit = ev.fname
        }
      }
      this.unitVisabled = false
    },
    // 查询发料方式列表
    async handleGetMaterials() {
      const { data: RES } = await queryViewItem({ viewName: 'SX_V_UNIT_ISSUETYPE' })
      this.storeData = RES.list
    },
    // 双击仓库弹窗
    warehouseSelectRow(item) {
      const { fstockId, fname } = item
      this.company.fpickStockId = fstockId
      this.company.fpickStock = fname
      this.openWarehouse = false
    }
  }
}
</script>

<style scoped lang="scss">
.elRow {
  display: flex;
  flex-wrap: wrap;
  .large {
    font-size: 14px;
    color: #606266;
    line-height: 40px;
    padding: 0 12px 0 12px;
    font-weight: 700;
  }
  .warehouse::before {
    content: '*';
    padding-right: 2px;
    color: red;
  }
  .input-width {
    width: 185px;
  }
  .el-icon-search {
    cursor: pointer;
  }
}
.el-table ::v-deep .el-table__body-wrapper {
  height: 480px;
}
</style>
